﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Azad;
using Azad.BCL;
using NazSoft.Framework;

public partial class BlankMasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Url.AbsolutePath.ToLowerInvariant().Contains("newsdetail.aspx"))
        {
            HeaderImagePlaceholder.Visible = false;
        }


        bool preview = Convert.ToBoolean(Request.QueryString["p"]);
        var menuName = Request["mn"] ?? string.Empty;

        SilverlightService silverlightService = new SilverlightService();
        var _today = DateTimeUtilities.GetDateFromQueryString().ToString();
        String logoInfoUrl = DateTimeUtilities.GetLogoDateFromQueryString(Request.QueryString);


        var _logoInformation = silverlightService.GetByCurrentId(_today, preview);
        if (_logoInformation != null)
        {
            CurrentMagDateContainer.Text = _logoInformation.FromDate.ToString("MMM dd") + " - " + _logoInformation.CurrentDate.ToString("MMM dd") + ", " + _logoInformation.CurrentDate.Year;

            this.Page.Title = "News Week | " + CurrentMagDateContainer.Text + " | " + menuName.Replace("-", " ").Capitalize();


            CurrentMagzine.HRef = _logoInformation.Url + "current-magazine";

            logoImage.Src = _logoInformation.Theme.LogoImage;
            string style = @"<style type=""text/css"">
                        .nav-bar {background-image: url('" + _logoInformation.Theme.MenuBackgroundImageUrl + @"');background-repeat: repeat-x;} 
                        .nav-bar a {color: #" + _logoInformation.Theme.FontColor + @";}
                        .NavigationRight a.button {color: #" + _logoInformation.Theme.FontColor + @";}
                        .Footer {background-image: url('" + _logoInformation.Theme.FooterImage + @"');background-repeat: no-repeat;}
                    </style>";

            this.Page.Header.Controls.Add(new Literal() { Text = style });

            HomeIconImage.ImageUrl = _logoInformation.Theme.HomeIconUrl;
            ContactUsIconImage.ImageUrl = _logoInformation.Theme.ContactUsIconUrl;
            CurrentMagazineIconImage.ImageUrl = _logoInformation.Theme.CurrentMagazineIconUrl;
        }

        #region bind commercials
        //if (_today)
        {
            var commercials = silverlightService.GetCommercial(DateTime.Now);
            if (commercials != null)
            {
                #region Comments
                //foreach (var commercial in commercials)
                //{
                //    switch (commercial.TypeId)
                //    {
                //        case 101:
                //            {
                //                CommercialVerticalLarge.InnerHtml += commercial.Script;
                //            }
                //            break;
                //        case 102:
                //            {
                //                CommercialLeftVertical1.InnerHtml += commercial.Script;
                //            }
                //            break;
                //        case 103:
                //            {
                //                CommercialLeftVertical2.InnerHtml += commercial.Script;
                //            }
                //            break;
                //        case 104:
                //            {
                //                CommercialRightVertical1.InnerHtml += commercial.Script;
                //            }
                //            break;
                //        case 105:
                //            {
                //                CommercialRightVertical2.InnerHtml += commercial.Script;
                //            }
                //            break;
                //        case 106:
                //            {
                //                CommercialBottomHorizontal.InnerHtml = commercial.Script;
                //            }
                //            break;
                //        default:
                //            break;
                //    }
                //}
                #endregion
                //rptLeftCommercial.DataSource = commercials.Where(f => f.TypeId == 102);
                //rptLeftCommercial.DataBind();
                //rptRightSection.DataSource = commercials.Where(f => f.TypeId == 101);
                //rptRightSection.DataBind();
                rptBottom.DataSource = commercials.Where(f => f.TypeId == 106);
                rptBottom.DataBind();
            }
        }
        #endregion
    }
}
